<?php
class Member extends  Controller
{
    function Member()
    {
        parent::Controller();
      
		header("Content-Type: text/html; charset=utf-8");
		
    }
    
    
    function logincheck()
    {
    	$username = $_POST["username"];
    	$password = $_POST["password"];
    	$isremember = $_POST["isremember"];
    	$query = $this->db->query("select userid,companyid,areaid,islock,password from ".table("users")." where nickname='".$username."'");
    	$result = array("error"=>1,"content"=>"用户名或密码错误");
    	
    	if($query->num_rows>0)
    	{
    		$rs = $query->row_array();
    		if($rs["password"]==md5($password))
    		{
    			$querycom = $this->db->query("select endtime from ".table("company")." where companyid=".$rs["companyid"]);
    			$companydata = $querycom->row_array();
    			$data = array(
    						"userid"=>$rs["userid"],
    						"companyid"=>$rs["companyid"],
    						"areaid"=>$rs["areaid"],
    						"cartend"=>$companydata["endtime"]
    			           );
    			$this->session->set_userdata("memberdata",$data);
    			$result = array("error"=>0,"content"=>"登陆成功");
    			if($isremember)
    			{ 
    				set_cookie("userid",$rs["userid"],86400*30);
    			}
    			
    		}
    		
    	}
    	
    	echo json_encode($result);
    }
    
    function checkuser()
    {
    	$result = array("success"=>1);
    	$showbox = $_POST["showbox"];
    	$re = checkcookie($_COOKIE,$this->session,$this->db);
    	$result = array("success"=>$re,"showbox"=>$showbox);
    	echo json_encode($result);
    }
    function logout()
    {
    	$this->session->set_userdata("memberdata","");
    	$this->session->set_userdata("shopcart","");
    	if(!empty($_COOKIE["userid"]))
    	{
    		set_cookie("userid","",-1);
    	}
    	echo json_encode(array("success"=>1));
    }
    
    
}    
?>